const User = require('./User')
const Manga = require('./Manga')
const Chapter = require('./Chapter')
const UserFavorite = require('./UserFavorite')

// 定义关联关系
User.belongsToMany(Manga, {
  through: UserFavorite,
  foreignKey: 'userId',
  as: 'favorites'
})

Manga.belongsToMany(User, {
  through: UserFavorite,
  foreignKey: 'mangaId',
  as: 'followers'
})

Manga.hasMany(Chapter, {
  foreignKey: 'mangaId',
  as: 'chapters'
})

Chapter.belongsTo(Manga, {
  foreignKey: 'mangaId',
  as: 'manga'
})

UserFavorite.belongsTo(User, {
  foreignKey: 'userId',
  as: 'user'
})

UserFavorite.belongsTo(Manga, {
  foreignKey: 'mangaId',
  as: 'manga'
})

module.exports = {
  User,
  Manga,
  Chapter,
  UserFavorite
}
